# module
SET(MODULE_NAME app)

# Set Module Path
SET(MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

# Include Direoctories
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECtORIES(${ECHO_ROOT_PATH})

# Link Directories
LINK_DIRECTORIES(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
LINK_DIRECTORIES(${ECHO_LIB_PATH})
LINK_DIRECTORIES(${ECHO_ROOT_PATH}/thirdparty/live2d/Cubism31SdkNative-EAP5/Core/lib/ios/)

# AddFrameWork Macro
MACRO(ADD_FRAMEWORK fwname)
	SET(FRAMEWORKS "${FRAMEWORKS} -framework ${fwname}")
ENDMACRO(ADD_FRAMEWORK)

# Get all project files recursively
FILE(GLOB_RECURSE HEADER_FILES *.h *.inl)
FILE(GLOB_RECURSE SOURCE_FILES *.cpp *.m *.mm)

SET(ALL_FILES ${HEADER_FILES} ${SOURCE_FILES})

# group source files
GROUP_FILES(ALL_FILES ${CMAKE_CURRENT_SOURCE_DIR})

# iOS platorm resources
SET(IOS_RESOURCE_FILES
	${MODULE_PATH}/Assets.xcassets
	${MODULE_PATH}/frame/Platform/iOS/Launch/Default-Portrait-375x667@2x.png
	${MODULE_PATH}/resources/data
)
SET_SOURCE_FILES_PROPERTIES(${IOS_RESOURCE_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)

# add framework
ADD_FRAMEWORK(MediaPlayer)
ADD_FRAMEWORK(AudioToolbox)
ADD_FRAMEWORK(CoreGraphics)
ADD_FRAMEWORK(QuartzCore)
ADD_FRAMEWORK(UIKit)
ADD_FRAMEWORK(GLKit)
ADD_FRAMEWORK(OpenGLES)
ADD_FRAMEWORK(OpenAL)
ADD_FRAMEWORK(CFNetwork)
ADD_FRAMEWORK(MobileCoreServices)
ADD_FRAMEWORK(SystemConfiguration)
ADD_FRAMEWORK(AVFoundation)
ADD_FRAMEWORK(AdSupport)
ADD_FRAMEWORK(CoreFoundation)
ADD_FRAMEWORK(CoreTelephony)
ADD_FRAMEWORK(CoreText)
ADD_FRAMEWORK(iAd)

ADD_FRAMEWORK(StoreKit)
ADD_FRAMEWORK(CoreData)
ADD_FRAMEWORK(CoreMedia)
ADD_FRAMEWORK(CoreMotion)
ADD_FRAMEWORK(Security)

SET(FRAMEWORKS "${FRAMEWORKS} -ObjC")
SET(CMAKE_EXE_LINKER_FLAGS ${FRAMEWORKS})
SET(CMAKE_OSX_ARCHITECTURES "${ARCHS_STANDARD}")

ADD_EXECUTABLE(${MODULE_NAME} MACOSX_BUNDLE ${HEADER_FILES} ${SOURCE_FILES} ${IOS_RESOURCE_FILES} CMakeLists.txt)

# Link Library
TARGET_LINK_LIBRARIES(${MODULE_NAME} engine)
TARGET_LINK_LIBRARIES(${MODULE_NAME} pugixml physx spine recast lua freeimage freetype zlib box2d)
TARGET_LINK_LIBRARIES(${MODULE_NAME} Live2DCubismCore)
TARGET_LINK_LIBRARIES(${MODULE_NAME} glslang spirv-cross)

SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${MODULE_PATH}/Frame/Platform/iOS/Info.plist)
#SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY[variant=Debug] "iPhone Developer:shuo zhang (KMY668K2JS)")
#SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY[variant=Release] "iPhone Developer:shuo zhang (KMY668K2JS)")
#SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE[variant=Debug] "bb1c4acc-2111-4504-a4eb-1a4ac4f26924")
#SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE[variant=Release] "bb1c4acc-2111-4504-a4eb-1a4ac4f26924")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++14")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME "launch")

# Messages
MESSAGE(STATUS "Configure iOS App success!")
